package com.wenhai.spring.resource;

import org.apache.commons.io.IOUtils;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.FileSystemResourceLoader;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.EncodedResource;

import java.io.IOException;

/**
 * {@link org.springframework.core.io.FileSystemResourceLoader} 示例
 *
 * @author wenhai
 * @date   2021/4/7
 * @see FileSystemResource
 * @see FileSystemResourceLoader
 */
public class EncodedFileSystemResourceLoaderDemo {
    public static void main(String[] args) throws IOException {
        String home = System.getProperty("user.dir");
        System.out.println(home);
        String currentJavaFilePath = home + "\\resource\\src\\main\\java\\com\\wenhai\\spring\\resource\\EncodedFileSystemResourceLoaderDemo.java";
        FileSystemResourceLoader fileSystemResource = new FileSystemResourceLoader();
        Resource resource = fileSystemResource.getResource(currentJavaFilePath);
        EncodedResource encodedResource = new EncodedResource(resource, "UTF-8");
        System.out.println(IOUtils.toString(encodedResource.getReader()));
    }
}
